﻿package com.skillscoach  {
	import alducente.services.WebService;
	
	import com.adobe.images.JPGEncoder;
	import com.skillscoach.ToolsPanel;
	
	import fl.transitions.Tween;
	import fl.transitions.easing.Strong;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.events.StatusEvent;
	import flash.events.TimerEvent;
	import flash.external.ExternalInterface;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.media.Microphone;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.net.navigateToURL;
	import flash.system.Security;
	import flash.utils.ByteArray;
	import flash.utils.Timer;
	
	import org.bytearray.micrecorder.MicRecorder;
	import org.bytearray.micrecorder.encoder.WaveEncoder;
	import org.bytearray.micrecorder.events.RecordingEvent;
	
	
	
	
	public class ImageConfig extends MovieClip{
		
		public var stageClip:MovieClip = this as MovieClip;
		public var toolsPanel:ToolsPanel;
		public var videoHolder:MovieClip;
		public var videoClip:MovieClip;
		public var videoClipHolder:MovieClip = new MovieClip();
		public var videoPlayPause:MovieClip;
		public var videoSeekbar:Seekbar;
		public var videoSeekbarPanel:MovieClip;
		public var bottomControlPanel:MovieClip;
		
		private var dataObj:DataObject = new DataObject();
		
		public var noOfSavedThumbs:uint = 0;
		public var noOfThumbsMoved:uint = 0;
		public var noOfThumbsLoaded:int = 0;
		public var thumbsInitPos:uint = 25;
		
		private var ws:WebService;
		private var mic:Microphone;
		private var recorder:MicRecorder;
		private var waveEncoder:WaveEncoder = new WaveEncoder();
		
		private var fps:int = 24;
		private var speed:Number = 1;
		private var playerTimer:Timer = new Timer((1000/fps)/speed);
		
		//-- For Configuration
		public var xmlLoader:URLLoader = new URLLoader();
		public var configXML:XML;
		private var curTime:Date;
		public var configXMLURL:String = "http://golfcoachlink.com/VideoAnalysis/11474_Analysis.xml?random="+getCurrentTime();
		
		//---- Video Details
		public var videoID:String;
		public var videoName:String;
		public var videoOwner:String;
		public var videoDescription:String;
		public var videoURL:String;
		public var imageURL:String;
		public var editType:String;
		public var videoAddedDate:String;
		public var videoDuration:String;
		private var soundBytes:ByteArray;
		private var paramObj:Object;
		private var deleteFrameNo:Number;	
		private var debug:Boolean = false;	
		      
		
		public function ImageConfig() {
			Security.allowDomain("*")
			this.addEventListener(Event.ENTER_FRAME,enterFrame);
		}
		
		private function enterFrame(e:Event)
		{
			var per:Number = Math.round((this.loaderInfo.bytesLoaded/this.loaderInfo.bytesTotal)*100)
			if(per == 100)
			{
				this.removeEventListener(Event.ENTER_FRAME,enterFrame);
				loadXml();
			}			
		}
		private function loadXml():void {
			paramObj = this.loaderInfo.parameters;
			if(!debug)
				configXMLURL = String("http://golfcoachlink.com/VideoAnalysis/11479_Analysis.xml?random="+getCurrentTime());
				//configXMLURL = String(paramObj.XMLFilePath+"?random="+getCurrentTime());
			xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
			xmlLoader.load(new URLRequest(configXMLURL));
		}
			
		
		private function onXMLLoadComplete(evt:Event):void {
			
			
			configXML = new XML(evt.target.data);
			videoID = configXML.video.videoInfo.id;
			videoName = configXML.video.videoInfo.name;
			videoOwner = configXML.video.videoInfo.owner;
			videoDescription = configXML.video.videoInfo.description;
			videoURL = configXML.video.videoInfo.videoURL;
			imageURL = configXML.video.videoInfo.imageURL;
			editType = configXML.video.videoInfo.editType;
			videoAddedDate = configXML.video.videoInfo.dateAdded;
			videoDuration = configXML.video.videoInfo.duration;
			
			
			trace(configXML)
			
			var imgArray:XMLList = configXML.video.videoEditInfo.savedAnalysis.analyse;
			for(var i:int = 0;i< imgArray.length();i++)
			{
			
				dataObj.setInfo(imgArray[i]);				
			}

			gotoAndStop(2);
			dataObj.waitMc = this.waitMc;
			specMc.alpha = 0;
			pleasewaitMc.visible = false;	
			//deleteConfirmMc.visible = false;	
			//deleteConfirmMc.yesBtn.addEventListener(MouseEvent.CLICK,deleteFrame);
			//deleteConfirmMc.noBtn.addEventListener(MouseEvent.CLICK,cancelDeleteFrame);
			infoMc.txt.text = " Id : "+videoID +" \n Name : "+videoName+" \n Owner : "+videoOwner +" \n Description : "+videoDescription+" \n Added Date : "+videoAddedDate +" \n Duration : "+videoDuration;
			aboutVideoBtn.addEventListener(MouseEvent.CLICK,showInfo);
			infoMc.okBtn.addEventListener(MouseEvent.CLICK,hideInfo);
			
			infoMc.visible = false;	
			waitMc.visible = false;	
			intScreen();	
			
		}
		private function showInfo(e:MouseEvent):void
		{
			infoMc.visible = true;	
		}
		private function hideInfo(e:MouseEvent):void
		{
			infoMc.visible = false;	
		}
		private function intScreen():void
		{
			videoHolder = stageClip.videoPlayerComp;
			//videoSeekbarPanel = stageClip.getChildByName("videoSeekbarPanel") as MovieClip;
			bottomControlPanel = stageClip.getChildByName("bottomControlPanel") as MovieClip;
			//videoPlayPause = bottomControlPanel.getChildByName("videoPlayBtn") as MovieClip;	
			
			//Add Tools Panel
			toolsPanel = stageClip.toolsPanel;
			toolsPanel.setTools();
			
			//Add Seekbar Panel
			//videoSeekbar = new Seekbar();
			//videoSeekbarPanel.addChild(videoSeekbar);
			//videoSeekbar.x = 15;
			//videoSeekbar.y = 15;
			
			
			//Draw Gradient BG
			var fType:String = GradientType.LINEAR;
			var bgGrads:Array = [0x1891D0, 0x126C9C];
			var bgAlphas:Array = [1,1];
			var bgRatios:Array = [0, 255];
			var bgMatr:Matrix = new Matrix();
			bgMatr.createGradientBox(1000,592,(Math.PI / 180) * 90,0,0);
			var sprdMethod:String = SpreadMethod.REFLECT;
			var bgSprite:Sprite = new Sprite();
			var g:Graphics = bgSprite.graphics;
				g.beginGradientFill(fType, bgGrads, bgAlphas, bgRatios, bgMatr, sprdMethod);
				g.drawRect(0,0,1000,592);
			stageClip.bgClip.addChild(bgSprite);
			
			ws = new WebService();
			ws.addEventListener(Event.CONNECT, wsdlConnected);
			if(debug)
				ws.connect("http://golfcoachlink.com/Services/VideoAnalysis.asmx?WSDL");
			else 
				ws.connect("http://golfcoachlink.com/Services/VideoAnalysis.asmx?WSDL");
				//ws.connect(String(paramObj.ServicePath)+"?WSDL");
			
			saveFrameCliked();
			completeAnalysisBtn.mouseEnabled = false;
			completeAnalysisBtn.alpha = .5;
			videoSeekbarPanel.analyseButton.mouseEnabled = false;
			videoSeekbarPanel.analyseButton.alpha = .5;
			
			bottomControlPanel.mouseEnabled = false;
			bottomControlPanel.mouseChildren= false;
			bottomControlPanel.alpha = .5;
			
			//--------
			var urlreq:URLRequest = new URLRequest("googlelogo.png");
			var logoLoader:Loader = new Loader();
			logoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadLogo);
			logoLoader.load(urlreq);
			
		}
		
		private function loadLogo(e:Event):void
		{
			var logo:Bitmap = e.target.content;
			
			
			if(logo.width > 160)
			{
				logo.height = (160/logo.width)*logo.height;
				logo.width = 160;
				
			}
			stageClip.logoHolder.addChild(logo);
			logo.x = (stageClip.logoHolder.width/2) - (logo.width/2);
			logo.y = (stageClip.logoHolder.height/2) - (logo.height/2);
			//this.logoHolder.addChild(e.content);
		}
		private function wsdlConnected(evt:Event):void{
			trace("web service  connected")
			loadVideo();
			
		}
		private function loadVideo():void
		{
			var url:URLRequest = new URLRequest(videoURL);
			//var url:URLRequest = new URLRequest("videos/golf.swf");
			//var url:URLRequest = new URLRequest("http://www.afreshtech.com/afreshtech.com/videoediting/videos/golf.swf");
			var videoLoader:Loader = new Loader();
			videoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onVideoLoad);
			videoLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);		
			videoLoader.load(url);		
			
			
		}
		function progressListener (e:ProgressEvent):void{
			try{
				MovieClip(e.target.content).stop();
			}catch(e){
				
			}
			//trace("Downloaded " + e.bytesLoaded + " out of " + e.bytesTotal + " bytes of video");
		}
		private function onVideoLoad(event:Event):void
		{
			videoClip = (event.target.content);
			videoClip.x = -videoClip.width/2;
			videoClip.y = -videoClip.height/2;
			
			videoClipHolder.addChild(videoClip);
			videoHolder.addChild(videoClipHolder);			
			videoClip.stop();	
			videoClip.gotoAndStop(1)
			
			noOfSavedThumbs = dataObj.frameArray.length;
			noOfThumbsLoaded = -1;
			
			loadImage(null);	
			
		}
		private function loadImage(e:Event):void
		{	
			if(noOfThumbsLoaded > -1)
			{
				var info:EditInfoObject = dataObj.getInfoByCuePoint(dataObj.frameArray[noOfThumbsLoaded]) as EditInfoObject;	
				info.image = LoaderInfo(e.target).content as Bitmap;
				info.image.x = -info.image.width/2;
				info.image.y = -info.image.height/2;
				if(info.cuePoint != 1)
					info.image.visible = false;
				videoHolder.addChild(info.image);
			}
			
			
			noOfThumbsLoaded++;
			
			if(noOfThumbsLoaded < noOfSavedThumbs)
			{
				info = dataObj.getInfoByCuePoint(dataObj.frameArray[noOfThumbsLoaded]) as EditInfoObject;	
				var urlRequest:URLRequest = new URLRequest(info.imageUrl);
				var imageLoader:Loader = new Loader();
				
				imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadImage);
				imageLoader.load(urlRequest);	
				
			}else {
				onAllImageLoad();
			}
			
		}
		
		private function onAllImageLoad():void
		{			
			bottomControlPanel.mouseEnabled = true;
			bottomControlPanel.mouseChildren= true;
			bottomControlPanel.alpha = 1;
			
			loadingVideoMc.visible = false;
			
			
			playerTimer.addEventListener(TimerEvent.TIMER,playingVideo);
			
			toolsPanel.loadTools(videoHolder,videoClipHolder)
			
			videoSeekbar.dataObj = dataObj;
			videoSeekbar.initControls(videoClip, videoPlayPause,playerTimer);
			
			//---- Slow Motion
			bottomControlPanel.slowMotionBack.addEventListener(MouseEvent.CLICK, slowMotionBackHandler);
			bottomControlPanel.slowMotionFront.addEventListener(MouseEvent.CLICK, slowMotionFrontHandler);
			
			bottomControlPanel.frameByFrameFront.addEventListener(MouseEvent.CLICK, frameByFrameFrontHandler);
			bottomControlPanel.frameByFrameBack.addEventListener(MouseEvent.CLICK, frameByFrameBackHandler);
			
			//--- Saved thumbs Navigation
			savedFramesHolder.thumbsNavBack.addEventListener(MouseEvent.CLICK, savedFramesThumbsMove);
			savedFramesHolder.thumbsNavFront.addEventListener(MouseEvent.CLICK, savedFramesThumbsMove);
			
			
			//---- Analyse Button
			
			videoSeekbarPanel.analyseButton.mouseEnabled = true;
			videoSeekbarPanel.analyseButton.alpha = 1;
			videoSeekbarPanel.analyseButton.addEventListener(MouseEvent.CLICK, startAnalyse);
			videoSeekbarPanel.saveFrameButton.addEventListener(MouseEvent.CLICK, saveFrame);
			completeAnalysisBtn.addEventListener(MouseEvent.CLICK, endAnalyse);
			
			

			
			//flvPlayback.source = "http://o-o.preferred.bom03s03.v8.lscache5.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Csource%2Calgorithm%2Cburst%2Cfactor%2Ccp&fexp=913536%2C916800%2C905266&algorithm=throttle-factor&itag=34&ip=112.0.0.0&burst=40&sver=3&signature=496B42674A7EC62036B25E3AEAB99DD202F6BB3D.07698ABC20D3A4BD2AE67134C383E6527F92A67B&source=youtube&expire=1326709955&key=yt1&ipbits=8&factor=1.25&cp=U0hRS1dLV19KT0NOMV9PRUFKOlJEWGJ2emdXWXls&id=58603d1e87c4d449&title=Golf%20Pitch%20Shot.flv";
			videoPlayPause.addEventListener(MouseEvent.CLICK, playPauseVideo);
			videoPlayPause.addEventListener(MouseEvent.ROLL_OVER, playPauseOver);
			videoPlayPause.addEventListener(MouseEvent.ROLL_OUT, playPauseOut);
			
			videoPlayPause.mouseChildren = false;	
			videoPlayPause.buttonMode = true;
			
			mic = Microphone.getMicrophone();
			
			
			
			if(mic == null)
			{
				
				//please  connect rou mobile
			}
			mic.addEventListener(StatusEvent.STATUS, micStatusHandler);
			mic.setUseEchoSuppression(true);
			mic.setLoopBack(false);
			
			if(mic.muted)
			{
				//please check your mic
			}
			
			recorder = new MicRecorder(waveEncoder, null, 100, 44, 5);
			recorder.addEventListener(RecordingEvent.RECORDING, recording);
			recorder.addEventListener(Event.COMPLETE, recordComplete);
			activity.addEventListener(Event.ENTER_FRAME, updateMeter);

			stageClip.recordBtn.addEventListener(MouseEvent.CLICK, toggleRecord);
			stageClip.recordBtn.buttonMode = true;
			
						
			generateThumb();
			
		}
		private function generateThumb():void {
			
			noOfSavedThumbs = dataObj.frameArray.length;
			
			while(savedFramesHolder.thumbnailStrip.numChildren>0)
			{
				savedFramesHolder.thumbnailStrip.removeChildAt(0)
			}
			
			for (var i:int = 0; i < noOfSavedThumbs; i++) 
			{
				var newThumb:MovieClip = new Thumbnail();
				savedFramesHolder.thumbnailStrip.addChild(newThumb);
				newThumb.name = "thumb"+i;
				newThumb.x = i*(newThumb.width+6);
	
				var info:EditInfoObject = dataObj.getInfoByCuePoint(dataObj.frameArray[i]) as EditInfoObject;
				var bitmap:Bitmap = new Bitmap(info.image.bitmapData);
				newThumb.closeBtn.cue = dataObj.frameArray[i];
				newThumb.closeBtn.addEventListener(MouseEvent.CLICK,showDeleteFrame)
				
				bitmap.width = 108;
				bitmap.height = 86;
				newThumb.thumbnailHolder.addChild(bitmap);
				
				
			}
			
		}
		private function deleteFrame(e:MouseEvent):void {
			
			completeAnalysisBtn.mouseEnabled = true;
			completeAnalysisBtn.alpha = 1;
			
			pleasewaitMc.visible = true;	
			ws.DeleteFrame(deleteFrameResponse,videoID,deleteFrameNo);
			dataObj.deleteInfoByCuePoint(deleteFrameNo);
			generateThumb();
			deleteConfirmMc.visible = false;
			
		}
		
		private function cancelDeleteFrame(e:MouseEvent):void {
			deleteConfirmMc.visible = false;				
		}
		private function showDeleteFrame(e:MouseEvent):void {
			deleteFrameNo = MovieClip(e.target).cue;
			deleteConfirmMc.visible = true;				
		}
		private function deleteFrameResponse(serviceRespone:XML):void
		{
			pleasewaitMc.visible = false;	
			trace("Web Service Result: deleteFrameResponse");
			trace(serviceRespone);
		}
		private function playingVideo(e:TimerEvent):void {
			
			
			dataObj.HideImageByCuePoint(videoClip.currentFrame);
			
			if(videoClip.currentFrame == videoClip.totalFrames)
			{
				videoClip.gotoAndStop(1)
			}else {
				videoClip.nextFrame();
			}
			for (var i:int = 0; i < dataObj.frameArray.length; i++) 
			{
				if(dataObj.frameArray[i] == videoClip.currentFrame)
				{
					dataObj.showImageByCuePoint(videoClip.currentFrame);
					playerTimer.stop();
					videoPlayPause.gotoAndStop(1)
				}
			}
			
			
		}
	
		
		//------record sound---//
		private function micStatusHandler(evt:StatusEvent):void
		{
			switch (evt.code) {
				case "Microphone.Muted":
					//check youe mic 
				break;
			}
		}
		private function toggleRecord(e:MouseEvent):void {
			
			if(MovieClip(stageClip.recordBtn).currentFrame == 1)
			{
				recorder.record();		
				activity.alpha = 1;
				specMc.alpha = 1;
				stageClip.recordBtn.gotoAndStop(2);
			}else {
				recorder.stop();
				activity.alpha = 0;
				specMc.alpha = 0;
				stageClip.recordBtn.gotoAndStop(1);
			}
			//recordBaring....
		}
		private function recording(e:RecordingEvent):void {
			//recordBaring....
		}
		private function updateMeter(e:Event):void
		{
			activity.gotoAndPlay(100 - mic.activityLevel);
		}
		
		private function recordComplete(e:Event):void {

			activity.gotoAndStop(1);
			soundBytes = (recorder.output);

		}
		
		private function savedFramesThumbsMove(evt:MouseEvent):void
		{
			trace(noOfSavedThumbs, noOfThumbsMoved);
			var strip:MovieClip = savedFramesHolder.thumbnailStrip;
			if(evt.target.name == "thumbsNavBack" && noOfSavedThumbs > 3 && noOfThumbsMoved > 0)
			{
				noOfThumbsMoved -= 1;
			}
			else if(evt.target.name == "thumbsNavFront" && noOfSavedThumbs > 3 && (noOfSavedThumbs-noOfThumbsMoved) > 3)
			{
				noOfThumbsMoved += 1;
			}
			
			var thumbTweenBack:Tween = new Tween(strip, "x", Strong.easeOut, strip.x,  25 - (118*noOfThumbsMoved), 1, true);
		}
		private function saveFrame(evt:MouseEvent):void
		{
			pleasewaitMc.visible = true;		
			
			var bounds:Rectangle = videoPlayerComp.getBounds( videoPlayerComp );
			var bd:BitmapData = new BitmapData( int( bounds.width + 0.5 ), int( bounds.height + 0.5 ), false, 0 );
			bd.draw( videoPlayerComp, new Matrix(1,0,0,1,-bounds.x,-bounds.y) );			
			var encoder:JPGEncoder = new JPGEncoder(80);
			var bytes:ByteArray = encoder.encode(bd);
				
			try{
				recorder.stop();
				activity.alpha = 0;
				stageClip.recordBtn.gotoAndStop(1);
			}catch(e)
			{
				
			}
				
 			var item:XML = <analyse />;
			item.analysedUser = "Rajmohan";
			item.dateAnalysed = "2/9/2012 6:22:00 PM";
			item.cuePoint = Number(videoClip.currentFrame);
			item.savedFrame = null;
			dataObj.setInfo(item);	
			
			var info:EditInfoObject = dataObj.getInfoByCuePoint(item.cuePoint) as EditInfoObject;	

			try{
				videoHolder.removeChild(info.image);	
			}catch(e){
				
			}
			info.image = new Bitmap(bd);
			info.image.x = -info.image.width/2;
			info.image.y = -info.image.height/2;
			videoHolder.addChild(info.image);
			
			generateThumb();
				
			saveFrameCliked();
			
			//bytes.writeUnsignedInt(bitmap.bitmapData.width);
			//bytes.writeBytes(bitmap.bitmapData.getPixels(bitmap.bitmapData.rect));
			//bytes.compress();
			if(soundBytes){
				ws.SaveFrame(saveFrameResponce, videoID , String(videoClip.currentFrame),Base64.encode(bytes),Base64.encode(soundBytes),"2/9/2012 6:22PM","Rajmohan");
			}else {
				ws.SaveFrame(saveFrameResponce, videoID , String(videoClip.currentFrame),Base64.encode(bytes),null,"2/9/2012 6:22PM","Rajmohan");
			}
		
		}
		
			
		private function saveFrameResponce(serviceRespone:XML):void{
			var str:String = String(serviceRespone.children().children().children());
			
			var info:EditInfoObject = dataObj.getInfoByCuePoint(videoClip.currentFrame) as EditInfoObject;
			info.soundUrl = str.substr(str.indexOf("|")+1);
			 pleasewaitMc.visible = false;
			 soundBytes = null;
			 videoClipHolder.rotation = 0;
			 toolsPanel.clearFrameChild();	 
		}
		private function loadSavedFrmae(url:String):void{
			
		}
		private function startAnalyse(evt:MouseEvent):void
		{
			toolsPanel.createChild();
			videoSeekbarPanel.saveFrameButton.mouseEnabled = true;
			videoSeekbarPanel.saveFrameButton.alpha = 1;
			stageClip.recordBtn.mouseEnabled = true;
			stageClip.recordBtn.alpha = 1;
			completeAnalysisBtn.mouseEnabled = true;
			completeAnalysisBtn.alpha = 1;
			videoSeekbarPanel.analyseButton.mouseEnabled = false;
			videoSeekbarPanel.analyseButton.alpha = .5;
			
			bottomControlPanel.mouseEnabled = false;
			bottomControlPanel.mouseChildren = false;
			bottomControlPanel.alpha = .5;
			
			toolsPanel.mouseChildren = true;
			toolsPanel.alpha = 1;
			playerTimer.stop();
			videoSeekbar.alpha = .5;
			videoPlayPause.alpha = .5;
			videoSeekbar.mouseChildren = false;
			videoPlayPause.enabled = false;
			videoPlayPause.mouseEnabled = false;
			videoPlayPause.gotoAndStop(1);		
			
		}
		private function endAnalyse(evt:MouseEvent):void
		{
			pleasewaitMc.visible = true;
			ws.CompleteAnalysis(completeAnalysisResponse,videoID);
		}
		private function completeAnalysisResponse(serviceRespone:XML):void
		{
			pleasewaitMc.visible = false;
			var urlRequest:URLRequest = new URLRequest("");
			urlRequest.method = URLRequestMethod.GET;
			var variable:URLVariables = new URLVariables();
			variable.videoId = videoID;
			urlRequest.data = variable;
			navigateToURL(urlRequest,"_self");
		}
		private function saveFrameCliked():void
		{
			bottomControlPanel.mouseEnabled = true;
			bottomControlPanel.mouseChildren= true;
			bottomControlPanel.alpha = 1;
			
			videoSeekbarPanel.analyseButton.mouseEnabled = true;
			videoSeekbarPanel.analyseButton.alpha = 1;
			
			videoSeekbarPanel.saveFrameButton.mouseEnabled = false;
			videoSeekbarPanel.saveFrameButton.alpha = .5;
			stageClip.recordBtn.mouseEnabled = false;
			stageClip.recordBtn.alpha = .5;
			
			toolsPanel.mouseChildren = false;
			toolsPanel.alpha = .5;
			//flvPlayback.play();
			videoSeekbar.mouseChildren = true;
			videoPlayPause.mouseEnabled = true;
			videoSeekbar.alpha = 1;
			videoPlayPause.alpha = 1;
		}
		private function slowMotionBackHandler(evt:MouseEvent):void
		{
			if(speed > .25)
			{
				speed -= .25
			}
			playerTimer.stop();
			playerTimer = new Timer((1000/fps)/speed)
			playerTimer.addEventListener(TimerEvent.TIMER,playingVideo);
			speedDisplyMc.txt.text = "X "+speed;
			
			if(videoPlayPause.currentFrame == 2)
			{
				playerTimer.start();
			}		
			
		}
		private function slowMotionFrontHandler(evt:MouseEvent):void
		{
			if(speed < 2)
			{
				speed += .25
			}

			playerTimer.stop();
			playerTimer = new Timer((1000/fps)/speed)
			playerTimer.addEventListener(TimerEvent.TIMER,playingVideo);
			speedDisplyMc.txt.text = "X "+speed;
			if(videoPlayPause.currentFrame == 2)
			{
				playerTimer.start();
			}
		}
		private function frameByFrameFrontHandler(evt:MouseEvent):void
		{
			dataObj.HideImageByCuePoint(videoClip.currentFrame);


			playerTimer.stop();
			videoPlayPause.gotoAndStop(1);
			videoClip.nextFrame();
			
			for (var i:int = 0; i < dataObj.frameArray.length; i++) 
			{
				if(dataObj.frameArray[i] == videoClip.currentFrame)
				{
					dataObj.showImageByCuePoint(videoClip.currentFrame);
				}
			}
			
		}
		private function frameByFrameBackHandler(evt:MouseEvent):void
		{
			dataObj.HideImageByCuePoint(videoClip.currentFrame);			
			
			playerTimer.stop();
			videoPlayPause.gotoAndStop(1)
			videoClip.prevFrame();
			
			for (var i:int = 0; i < dataObj.frameArray.length; i++) 
			{
				if(dataObj.frameArray[i] == videoClip.currentFrame)
				{
					dataObj.showImageByCuePoint(videoClip.currentFrame);
				}
			}
			
		}
		/*private function gotoFrame(evt:MouseEvent):void
		{
			dataObj.HideImageByCuePoint(videoClip.currentFrame);			
			
			playerTimer.stop();
			videoPlayPause.gotoAndStop(1)
			videoClip.gotoAndStop();
			
			for (var i:int = 0; i < dataObj.frameArray.length; i++) 
			{
				if(dataObj.frameArray[i] == videoClip.currentFrame)
				{
					dataObj.showImageByCuePoint(videoClip.currentFrame);
				}
			}
			
		}*/
		private function playPauseVideo(evt:MouseEvent):void
		{
			if(evt.target.currentFrame == 1)
			{
				evt.target.gotoAndStop(2);
				playerTimer.start();
			}
			else
			{
				evt.target.gotoAndStop(1);
				playerTimer.stop();
			}
		}
		
		private function playPauseOver(evt:MouseEvent):void
		{
			evt.target.alphaLayer.alpha = .3;
			
		}
		private function playPauseOut(evt:MouseEvent):void
		{
			evt.target.alphaLayer.alpha = 0;
			
		}
		private function getCurrentTime():String
		{
			curTime = new Date();
			return String(curTime.getTime());
		}
		
		
	}
	
}
